package gwt.immunology.server.converter;

import static gwt.immunology.shared.GenericDtoKeys.ID;
import static gwt.immunology.shared.GenericDtoKeys.CREATION_DATE;
import static gwt.immunology.shared.GenericDtoKeys.OTHER_INFO;
import gwt.immunology.shared.GenericDto;
import gwt.immunology.shared.ResultSetDto;

import java.util.List;

import models.MedicineCard;

public class MedicineCardDtoConverter {

    public static GenericDto convertMedicineCardToGenericDto(MedicineCard medicineCard) {
	GenericDto result = new GenericDto();
	if (medicineCard != null) {
	    result.put(ID, medicineCard.medicineCardId);
	    result.put(CREATION_DATE, medicineCard.creationDate);
	    result.put(OTHER_INFO, medicineCard.otherInfo);
	}
	return result;
    }

    public static MedicineCard convertGenericDtoToMedicineCard(GenericDto medicineCardDto) {
	MedicineCard result = null;
	if (medicineCardDto != null && !medicineCardDto.isEmpty()) {
	    result = new MedicineCard();
	    result.medicineCardId = medicineCardDto.getLong(ID);
	    result.creationDate = medicineCardDto.getDate(CREATION_DATE);
	    result.otherInfo = medicineCardDto.getString(OTHER_INFO);
	}
	return result;
    }

    public static ResultSetDto convertMedicineCardsToResultSetDto(List<MedicineCard> medicineCards) {
	ResultSetDto result = new ResultSetDto();
	if (medicineCards != null && !medicineCards.isEmpty()) {
	    for (MedicineCard medicineCard : medicineCards) {
		GenericDto medicineCardDto = convertMedicineCardToGenericDto(medicineCard);
		result.add(medicineCardDto);
	    }
	}
	return result;
    }

}
